package collectionFramework;

import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;

class Employee {
	private int id;
	private String name;
	private float salary;
	private LinkedList<Employee> ll = new LinkedList<Employee>();
	private Scanner obj = new Scanner(System.in);

	public Employee() {
	}

	public Employee(int id, String name, float salary) {
		this.id = id;
		this.name = name;
		this.salary = salary;
	}

	void addItem() {
		System.out.print("Employee ID: ");
		this.id = obj.nextInt();

		System.out.print("Employee Name: ");
		this.name = obj.next();

		System.out.print("Employee Salary: ");
		this.salary = obj.nextFloat();
		ll.add(new Employee(this.id, this.name, this.salary));
	}

	void removeItem() {
		System.out.println("Enter the position of the object to remove");
		int pos = obj.nextInt();
		ll.remove(pos - 1);
	}

	// Display using toString method
	void display() {
		ListIterator<Employee> li = ll.listIterator();
		while (li.hasNext())
			System.out.println(li.next());
	}

	@Override
	public String toString() {
		return "ID=" + id + "\nName=" + name + "\nSalary=" + salary;
	}

	// Alternative display method
	/*
	 * void displayElement() { ListIterator<Employee> li = ll.listIterator();
	 * while (li.hasNext()) { Object obj = li.next(); Employee emp = (Employee)
	 * obj; emp.display(); } }
	 * 
	 * void display() { System.out.println("ID=" + id);
	 * System.out.println("Name=" + name); System.out.println("Salary=" +
	 * salary); }
	 */
}

public class Demo {

	public static void main(String[] args) {
		Scanner obj = new Scanner(System.in);
		String con;
		Employee emp = new Employee();
		do {
			System.out.println("1: Add");
			System.out.println("2: Remove");
			System.out.println("3: Disp");
			System.out.print("Choice: ");
			int ch = obj.nextInt();
			switch (ch) {
			case 1:
				emp.addItem();
				break;
			case 2:
				emp.removeItem();
				break;
			case 3:
				emp.display();
				break;
			}
			System.out.print("Continue (yes/no): ");
			con = obj.next();
		} while (con.equalsIgnoreCase("yes"));
	}
}
